<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客注册页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/register.css">

</head>

<body>
<div class="nav">
    <img src="pic/logo2.jpg" alt="">
    <span class="blog-title">我的博客系统</span>
    <div class="space"></div>
    <a class="nav-span" href="blog_list.html">主页</a>
    <a class="nav-span" href="blog_edit.html">写博客</a>
</div>

<div class="container-login">
    <div class="login-dialog">
        <h3>注册</h3>
        <!-- ... existing code ... -->
        <div class="row">
            <span>用户名</span>
            <input type="text" name="username" id="username" placeholder="请输入用户名(必填)">
        </div>
        <div class="row">
            <span>密码</span>
            <input type="password" name="password" id="password" placeholder="请输入密码(必填)">
        </div>
        <div class="row">
            <span>确认密码</span>
            <input type="password" name="confirmPassword" id="confirmPassword" placeholder="请输入确认密码(必填)">
        </div>
        <div class="row">
            <span>Github地址</span>
            <input type="text" name="githubUrl" id="githubUrl" placeholder="请输入Github地址(选填）")>
        </div>
        <!-- 修改按钮布局，使其与登录页面风格一致 -->
        <div class="row button-row">
            <button id="register" onclick="register()">注册</button>
            <button id="backToLogin" onclick="location.href='blog_login.html'">返回登录</button>
        </div>
    </div>
</div>

<script src="js/jquery.min.js"></script>
<script>
    // ... existing code ...
    function register() {
        // 获取表单数据
        var username = $("#username").val();
        var password = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        var githubUrl = $("#githubUrl").val();

        if (!username || !password || !confirmPassword) {
            alert("请填写完整信息");
            return;
        }

        if (password !== confirmPassword) {
            alert("两次输入的密码不一致");
            return;
        }

        // 发送注册请求
        $.ajax({
            type: "POST",
            url: "/user/register",
            data: {
                userName: username,
                password: password,
                githubUrl: githubUrl,
            },
            success: function (result) {
                if (result.code == "SUCCESS" && result.data == null) {
                     location.href = "blog_login.html";
                }else {
                    alert(result.msg);
                }
            }
        });
    }
</script>
</body>

</html>